package com.tiancheng.trade.payment.util;

import com.alibaba.fastjson.JSONObject;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.JWTDecodeException;
import com.auth0.jwt.interfaces.DecodedJWT;
import org.apache.commons.codec.binary.StringUtils;

import java.io.ByteArrayInputStream;
import java.security.PublicKey;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.security.interfaces.ECPublicKey;
import java.util.Base64;

/**
 * @Author: likailun
 * @Description: jwt工具类
 * @Date: create in 2022/6/13 5:11 下午
 */
public class JwtUtils {

    public static String verify(String payload){
        try {
            // 拿到 header 中 x5c 数组中第一个
            //TokenUtils.splitToken(payload);
            DecodedJWT decodedJWT = JWT.decode(payload);
            String header = new String(Base64.getDecoder().decode(decodedJWT.getHeader()));
            String x5c0 = JSONObject.parseArray(JSONObject.parseObject(header).get("x5c").toString()).get(0).toString();
            // 获取公钥
            PublicKey publicKey = getPublicKeyByX5c(x5c0);
            // 验证 token
            Algorithm algorithm = Algorithm.ECDSA256((ECPublicKey) publicKey, null);
            algorithm.verify(decodedJWT);

            return decodedJWT.getPayload();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
        String signedPayLoad="eyJhbGciOiJFUzI1NiIsIng1YyI6WyJNSUlFTURDQ0E3YWdBd0lCQWdJUWFQb1BsZHZwU29FSDBsQnJqRFB2OWpBS0JnZ3Foa2pPUFFRREF6QjFNVVF3UWdZRFZRUURERHRCY0hCc1pTQlhiM0pzWkhkcFpHVWdSR1YyWld4dmNHVnlJRkpsYkdGMGFXOXVjeUJEWlhKMGFXWnBZMkYwYVc5dUlFRjFkR2h2Y21sMGVURUxNQWtHQTFVRUN3d0NSell4RXpBUkJnTlZCQW9NQ2tGd2NHeGxJRWx1WXk0eEN6QUpCZ05WQkFZVEFsVlRNQjRYRFRJeE1EZ3lOVEF5TlRBek5Gb1hEVEl6TURreU5EQXlOVEF6TT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WpveE5qVTBPVEUwTnpFNE1EQXdMQ0p2Y21sbmFXNWhiRkIxY21Ob1lYTmxSR0YwWlNJNk1UWTFORGt4TkRjeE9EQXdNQ3dpY1hWaGJuUnBkSGtpT2pFc0luUjVjR1VpT2lKRGIyNXpkVzFoWW14bElpd2lhVzVCY0hCUGQyNWxjbk5vYVhCVWVYQmxJam9pVUZWU1EwaEJVMFZFSWl3aWMybG5ibVZrUkdGMFpTSTZNVFkxTlRNME16YzNNems0TVN3aVpXNTJhWEp2Ym0xbGJuUWlPaUpRY205a2RXTjBhVzl1SW4wLnVDbDYxUjg0ZVY2SHlzWDVGNHZjd21pWFlrNWgwejVqMENQZldOWkQ2Z19rbEUwMnllQVdjRDhfcGpvSWVUVjdSQjJ3TWRqRGY1bG9aUUZsRjZoMnFnIn0sInZlcnNpb24iOiIyLjAiLCJzaWduZWREYXRlIjoxNjU1MzQzNzczOTkzfQ.nwtnBCN3mUfqKMBUPxr2i1_I5dJ6NtyQLLX9C4QAVeqI-WJUbfCEftrwSyPX0DrrwBgw1hBvkmZZp8qyLcHn6A";
        final String aNew = verifyNew(signedPayLoad);
        System.out.println(aNew);
    }

    public static String verifyNew(String token){
        String[] parts = token.split("\\.");
        if (parts.length == 2 && token.endsWith(".")) {
            parts = new String[]{parts[0], parts[1], ""};
        }
        String payloadJson;
        try {
            payloadJson = StringUtils.newStringUtf8(org.apache.commons.codec.binary.Base64.decodeBase64(parts[1]));
            return payloadJson;
        } catch (NullPointerException var6) {
            throw new JWTDecodeException("The UTF-8 Charset isn't initialized.", var6);
        } catch (IllegalArgumentException var7) {
            throw new JWTDecodeException("The input is not a valid base 64 encoded string.", var7);
        }
    }



    public static String getFromBASE64(String payload){
        return new String(Base64.getUrlDecoder().decode(payload));
    }

    public static PublicKey getPublicKeyByX5c(String x5c) throws CertificateException {
        byte[] x5c0Bytes = Base64.getDecoder().decode(x5c);
        CertificateFactory fact = CertificateFactory.getInstance("X.509");
        X509Certificate cer = (X509Certificate) fact.generateCertificate(new ByteArrayInputStream(x5c0Bytes));
        return cer.getPublicKey();
    }

}
